package Classes.GameUtils// ActionScript file
{
	import MV_BMP.MovieClip_BMP;
	
	import PaperMan.BMPMC_Cartoon;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.system.ApplicationDomain;
	
	public class GU_GetBMPMC
	{
		private static var _BMPMCs:Object;
		/**
		 *获得位图动画 
		 * @param picStr
		 * @param tmpSign
		 * @param dynamic
		 * @return 
		 * 
		 */		
		public static function getBMPMC(picStr:String,tmpSign:Boolean=true):Sprite
		{
			var returnSprite:Sprite=new Sprite;
			var getCartoon:MovieClip_BMP;
			if(tmpSign)
			{
				getCartoon=creatBMPMC(picStr,tmpSign);
			}
			else
			{
				var checkCartoon:MovieClip_BMP=BMPMCs[picStr];
				if(!checkCartoon)
				{
					checkCartoon=creatBMPMC(picStr,tmpSign);
					BMPMCs[picStr]=checkCartoon;
				}
				getCartoon=checkCartoon.clone();
				getCartoon.x=checkCartoon.x;
				getCartoon.y=checkCartoon.y;
			}
			getCartoon.play();
			returnSprite.addChild(getCartoon);
			return returnSprite;
		}
		
		private static function creatBMPMC(picStr:String,dynamic:Boolean):MovieClip_BMP
		{
			var mcCartoon:MovieClip=new (ApplicationDomain.currentDomain.getDefinition(picStr) as Class);
			var renderRectangle:DisplayObject=mcCartoon.getChildAt(0);
			var excursionPoint:Point=new Point(renderRectangle.x,renderRectangle.y);
			var returnCartoon:MovieClip_BMP=new MovieClip_BMP;
			returnCartoon.turnFrom(mcCartoon,excursionPoint,dynamic?-1:0);
			returnCartoon.x=excursionPoint.x;
			returnCartoon.y=excursionPoint.y;
			return returnCartoon;
		}
		
		/**
		 *获得矢量动画或矢量图 
		 * @param picStr
		 * @return 
		 * 
		 */		
		public static function getVectorSP(picStr:String):Sprite
		{
			if(!ApplicationDomain.currentDomain.hasDefinition(picStr))
			{
				throw new Error("尚未载入该图资源");
			}
			var returnSP:Sprite=new (ApplicationDomain.currentDomain.getDefinition(picStr) as Class);
			return returnSP;
		}
		
		/*getter & setter*/
		public static function get BMPMCs():Object
		{
			if(!_BMPMCs)_BMPMCs=new Object;
			return _BMPMCs;
		}
		
	}
}